package com.example.fw;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;

public abstract class WebDriverHelperBase extends HelperBase{
	
	protected WebDriver driver;

	public WebDriverHelperBase(AppManager manager){
		super(manager);
		this.driver = manager.getDriver();
	}

	protected void click(By locator) {
		getElement(locator).click();
	}

	private WebElement getElement(By locator) {
		return driver.findElement(locator);
	}
	
	protected List<WebElement> getElements(By locator) {
		return driver.findElements(locator);		
	}

	protected void type(By locator, String text) {
		if (text != null){
			getElement(locator).clear();
			getElement(locator).sendKeys(text);
		}
	}

	protected void select(String text, By locator) {
		if (text != null) {
			new Select(getElement(locator)).selectByVisibleText(text);
		}
	}
	
	protected void selectByIdItem(String id, By locator) {
		new Select(getElement(locator)).selectByIndex(Integer.parseInt(id));
	}
}
